package app.excel.cartoon.year;

import java.io.File;

import app.esb.common.DBExcutor;
import app.excel.cartoon.index.ExcelCartoonIndex;
import app.web.spe.CartoonSPE;
import cn.lily.com.file.excel.io.ExcelWriter;

/**
 * 年份Excel导出
 * @author JiaJ
 *
 */
public class ExcelCartoonYear {
	
	/**
	 * 文件路径
	 */
	private String filePath;
	
	/**
	 * Excel处理类
	 */
	private ExcelWriter excelWriter;
	
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	/**
	 * 数据导出
	 */
	public void export(){
		
		//初始化文件
		this.instFile();
		
		this.excelWriter = new ExcelWriter(this.filePath);		
		this.excelWriter.inst(100);
		
		//完成首页
		ExcelCartoonIndex.buildSheet(excelWriter);
		
		ExcelYearData data = new ExcelYearData();
		data.instData();
		data.excuteData();
		
		int beginYear = CartoonSPE.MAX_YEAR;
		int endYear = CartoonSPE.MIN_YEAR;
		
		int i=0;
		for(;beginYear>=endYear;beginYear--){	
			
			String active = beginYear+"";	
			
			ExcelYearSheet sheet = new ExcelYearSheet();
			sheet.setSheetIdx(i+1);
			sheet.setSheetName(active);
			sheet.setData(data);
			
			sheet.writeSheet(this.excelWriter);
			
			i++;		
		}
		
		//写出
		this.excelWriter.write();
		
	}
	
	/**
	 * 初始化文件
	 */
	private void instFile(){
		File file = new File(this.filePath);
		if(file.exists()){
			file.delete();
		}
		System.out.println("初始化文件完成.........");
	}
	
	/**
	 * 释放
	 */
	public void free(){
		if(this.excelWriter != null){
			this.excelWriter.free();
		}
	}
	
	public static void main(String[] args) {
		
		DBExcutor.createEnv();
		
		ExcelCartoonYear excelWord = new ExcelCartoonYear();
		
		excelWord.setFilePath("D:/aa.xlsx");
		
		excelWord.export();
		
		excelWord.free();
		
	}
	
}
